<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
</head>
<body>
<div class="x-body">
    <form class="layui-form">
        <!--user的userId放入隐藏域-->
        <input type="hidden" name="staffId" id="staffId" th:value="${staff.staffId}">

        <div class="layui-form-item">
            <label for="staffUsername" class="layui-form-label">
                用户名
            </label><span class="x-red">不可修改</span>
            <div class="layui-input-inline">
                <input type="text" th:value="${staff.staffUsername}" disabled="disabled" id="staffUsername" name="staffUsername"  required  lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="currentPassword" class="layui-form-label">
                <span class="x-red">*</span>当前密码
            </label>
            <div class="layui-input-inline">
                <input type="password"  id="currentPassword" name="currentPassword"  lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="newPassword" class="layui-form-label">
                <span class="x-red">*</span>新密码
            </label>
            <div class="layui-input-inline">
                <input type="password"  id="newPassword" name="newPassword"  lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <button  class="layui-btn" lay-filter="save" lay-submit="">
            保存
        </button>

    </form>
</div>
</div>
</body>
</html>
<script>

    //form表单,layer弹出框
    layui.use(['form','layer'],function () {
        $ = layui.jquery;
        var form = layui.form,layer = layui.layer;
    //监听提交
        form.on('submit(save)',function (data) {
            console.log(data);

            $.ajax({
                url:"/staff/save/editPassword",
                type:"POST",
                dataType:"json",
                data:{"currentPassword":$("#currentPassword").val(),"newPassword":$("#newPassword").val()},
                success: function(data){
                    if(data==true){
                        layer.alert("修改成功", {icon: 6},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            //刷新
                            parent.window.location.replace("/manager/main")
                        });
                    }else{
                        layer.msg('当前密码错误，请重试!',{icon: 6,time:1000});
                    }
                }

            })

            return false;
        });
    });

    //

</script>